import { E_BattleUnitAttr } from "../BattleConst";

/**
 * 战斗单位属性管理器
 */
export default class BattleUnitAttrMgr {
    /**当前属性 */
    private _attrs: Map<E_BattleUnitAttr, number> = new Map();

    /**初始属性 */
    private _initialAttrs: Map<E_BattleUnitAttr, number> = new Map();

    public getAttr(attrType: E_BattleUnitAttr): number {
        return this._attrs.get(attrType) || 0
    }

    public getInitialAttr(attrType: E_BattleUnitAttr): number {
        return this._initialAttrs.get(attrType) || 0
    }

    public addAttr(attrType: E_BattleUnitAttr, num: number) {
        let val = this._attrs.get(attrType) || 0;
        val += num;
        this._attrs.set(attrType, val);
    }

    public setInitAttrs(attrs: any) {
        for (let key in attrs) {
            this._initialAttrs.set(parseInt(key), attrs[key])
            this._attrs.set(parseInt(key), attrs[key])
        }
    }
}